﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Portal.Xml.Utility;

namespace Portal.Systems.Model
{
    public class RoleCls
    {
        public string RoleId;
        public string RoleName;
        public string RoleCode;
        public string SyncRoleId;
        public UserCls[] Users = new UserCls[0];
        public int TotalUsers = 0;
    }

    public class RoleParser
    {
        public static RoleCls CreateInstance()
        {
            //tao 1 class trang....
            RoleCls oRoleCls = new RoleCls();
            return oRoleCls;
        }

        public static RoleCls ParseFromXml(string XmlData)
        {
            DataSet ds = XmlUtility.GetDataSetFromXml(XmlData);
            RoleCls oRoleCls = ParseFromDataRow(ds.Tables[0].Rows[0]);
            return oRoleCls;
        }


        public static RoleCls ParseFromDataRow(DataRow dr)
        {
            RoleCls ORoleCls = new RoleCls();
            ORoleCls.RoleId = (string)dr["RoleId"];
            ORoleCls.RoleName = (string)dr["RoleName"];
            ORoleCls.RoleCode = (string)dr["RoleCode"];
            
            try
            {
                ORoleCls.SyncRoleId = (string)dr["SyncRoleId"];
            }
            catch { }
            try
            {
                ORoleCls.TotalUsers = (int)dr["TotalUsers"];
            }
            catch { }
            return ORoleCls;
        }

        public static RoleCls[] ParseFromDataTable(DataTable dtTable)
        {
            RoleCls[] Roles = new RoleCls[dtTable.Rows.Count];
            for (int iIndex = 0; iIndex < dtTable.Rows.Count; iIndex++)
            {
                Roles[iIndex] = ParseFromDataRow(dtTable.Rows[iIndex]);
            }

            return Roles;
        }
    }
}


